package ink.lovejinhu.leetcode;

import ink.lovejinhu.common.Node;

import java.util.ArrayList;
import java.util.List;

public class Solution_0590 {
    /**
     * N叉树的后序遍历
     *
     * @param root
     * @return
     */
    public List<Integer> postorder(Node root) {
        this.dfs(root);


        return res;

    }

    public List<Integer> res = new ArrayList<>();

    public void dfs(Node root) {
        if (root == null) {
            return;
        }
        if (root.children == null) {
            res.add(root.val);
        }
        for (int i = 0; i < root.children.size(); i++) {
            dfs(root.children.get(i));
        }
        res.add(root.val);
    }
}
